/**
 * 输出方法日日志
 * @param {*} type
 */
export const log = type => {
    return (target, name, descriptor) => {
        console.log(target);
        console.log(name);
        console.log(descriptor);
        const method = descriptor.value
        descriptor.value = (...args) => {
            console.info(`(${type}) 正在执行: ${name}(${args}) = ?`)
            let ret
            try {
                ret = method.apply(target, args)
                console.info(`(${type}) 成功 : ${name}(${args}) => ${ret}`)
            } catch (error) {
                console.error(`(${type}) 失败: ${name}(${args}) => ${error}`)
            }
            return ret
        }
    }
}


// utils/decorator.js
/**
 * 表单校验
 * @param {String} formElKey - 表单el
 */
export const formValidation = (formElKey = 'formEl') => {
    return (target, name, descriptor) => {
        const method = descriptor.value
        descriptor.value = async function () {
            const _this = this._isVue ? this : target
            const isValidate = _this.$refs[formElKey]?.validate
            if (isValidate) {
                const [, res] = await isValidate()
                console.log(res);
                if (!res) return false
            }
            return method.apply(_this, arguments)
        }
    }
}